package com.daur.scwcd.test.servlets;

import java.io.IOException;

import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class ConfigContextTestServlet extends HttpServlet {

	private static final long serialVersionUID = 5813980366889787536L;

	private static final String SERVLET_CONFIG_PARAM_ONE_NAME = "ConfigParamOne";
	private static final String SERVLET_CONTEXT_PARAM__ONE_NAME = "ContextParamOne";

	@Override
	public void init(ServletConfig config) throws ServletException {
		System.out.println("====>> One");
		System.out.println(config.getInitParameter(SERVLET_CONFIG_PARAM_ONE_NAME));
		System.out.println(config.getServletContext().getInitParameter(SERVLET_CONTEXT_PARAM__ONE_NAME));
		super.init(config);
	}

	@Override
	public void init() throws ServletException {
		System.out.println("====>> Two");
		super.init();
	}

	@Override
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		String configParam = getServletConfig().getInitParameter(SERVLET_CONFIG_PARAM_ONE_NAME);
		String contextParam = getServletContext().getInitParameter(SERVLET_CONTEXT_PARAM__ONE_NAME);
		response.getWriter().println("Servlet configParamOne = " + configParam);
		response.getWriter().println("Servlet contextParamOne = " + contextParam);
	}

}
